using B.S.XZYData.ErrorCode;
using MediatR;
using System;
using System.Collections.Generic;

namespace B.S.XZYData.Api.Wrter.Application.Command.WorkOrder
{
    /// <summary>
    /// 保存工单命令（主表+工序表一起保存）
    /// </summary>
    public class SaveWorkOrderCommand : IRequest<ApiResult<int>>
    {
        /// <summary>
        /// 工单ID（0表示新增，>0表示编辑）
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 工单编号
        /// </summary>
        public string Code { get; set; }

        /// <summary>
        /// 来源计划明细ID
        /// </summary>
        public int? PlanItemId { get; set; }

        /// <summary>
        /// 工艺路线ID
        /// </summary>
        public int? RouteId { get; set; }

        /// <summary>
        /// 产品编号
        /// </summary>
        public string? ProductCode { get; set; }

        /// <summary>
        /// 产品名称
        /// </summary>
        public string? ProductName { get; set; }

        /// <summary>
        /// 规格
        /// </summary>
        public string? Spec { get; set; }

        /// <summary>
        /// 单位
        /// </summary>
        public string? Unit { get; set; }

        /// <summary>
        /// 计划数量
        /// </summary>
        public int? PlannedQuantity { get; set; }

        /// <summary>
        /// 实际数量
        /// </summary>
        public int? ActualQuantity { get; set; }

        /// <summary>
        /// 良品数量
        /// </summary>
        public int? GoodQuantity { get; set; }

        /// <summary>
        /// 不良品数量
        /// </summary>
        public int? BadQuantity { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public string? Status { get; set; }

        /// <summary>
        /// 计划开始时间
        /// </summary>
        public DateTime? PlannedStartTime { get; set; }

        /// <summary>
        /// 计划结束时间
        /// </summary>
        public DateTime? PlannedEndTime { get; set; }

        /// <summary>
        /// 实际开始时间
        /// </summary>
        public DateTime? ActualStartTime { get; set; }

        /// <summary>
        /// 实际结束时间
        /// </summary>
        public DateTime? ActualEndTime { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string? Remark { get; set; }

        /// <summary>
        /// 操作人
        /// </summary>
        public string OperateBy { get; set; }

        /// <summary>
        /// 工单工序列表
        /// </summary>
        public List<SaveWorkOrderProcessCommand> Processes { get; set; } = new List<SaveWorkOrderProcessCommand>();
    }

    /// <summary>
    /// 保存工单工序命令
    /// </summary>
    public class SaveWorkOrderProcessCommand
    {
        /// <summary>
        /// 工序ID（0表示新增，>0表示编辑）
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 所属工单ID
        /// </summary>
        public int WorkOrderId { get; set; }

        /// <summary>
        /// 顺序号
        /// </summary>
        public int Sequence { get; set; }

        /// <summary>
        /// 工序编号
        /// </summary>
        public string ProcessCode { get; set; }

        /// <summary>
        /// 工序名称
        /// </summary>
        public string ProcessName { get; set; }

        /// <summary>
        /// 计划数量
        /// </summary>
        public int? PlannedQuantity { get; set; }

        /// <summary>
        /// 已报工数
        /// </summary>
        public int? ReportedQuantity { get; set; }

        /// <summary>
        /// 良品数
        /// </summary>
        public int? GoodQuantity { get; set; }

        /// <summary>
        /// 不良品数
        /// </summary>
        public int? BadQuantity { get; set; }

        /// <summary>
        /// 报工配比
        /// </summary>
        public decimal? Ratio { get; set; }

        /// <summary>
        /// 计划开始时间
        /// </summary>
        public DateTime? PlannedStartTime { get; set; }

        /// <summary>
        /// 计划结束时间
        /// </summary>
        public DateTime? PlannedEndTime { get; set; }

        /// <summary>
        /// 实际开始时间
        /// </summary>
        public DateTime? ActualStartTime { get; set; }

        /// <summary>
        /// 实际结束时间
        /// </summary>
        public DateTime? ActualEndTime { get; set; }

        /// <summary>
        /// 状态
        /// </summary>
        public string? Status { get; set; }

        /// <summary>
        /// 是否删除（用于标识需要删除的工序）
        /// </summary>
        public bool IsDeleted { get; set; }

        /// <summary>
        /// 工序分派列表
        /// </summary>
        public List<SaveWorkOrderAssignCommand> Assigns { get; set; } = new List<SaveWorkOrderAssignCommand>();
    }

    /// <summary>
    /// 保存工序分派命令
    /// </summary>
    public class SaveWorkOrderAssignCommand
    {
        /// <summary>
        /// 分派ID（0表示新增，>0表示编辑）
        /// </summary>
        public int Id { get; set; }

        /// <summary>
        /// 工单工序ID
        /// </summary>
        public int WorkOrderProcessId { get; set; }

        /// <summary>
        /// 员工ID
        /// </summary>
        public int EmployeeId { get; set; }

        /// <summary>
        /// 员工姓名
        /// </summary>
        public string EmployeeName { get; set; }

        /// <summary>
        /// 分派数量
        /// </summary>
        public int Quantity { get; set; }

        /// <summary>
        /// 是否删除（用于标识需要删除的分派）
        /// </summary>
        public bool IsDeleted { get; set; }
    }
}
